package bak;
// 判断一个可达问题，其次是最优化问题
// 判定是建立在最优化的前提之上
public class CoinsExchange1 {

	interface CheckType {
		final int Gold = 0;
		final int Siver = 1;
	}

	// int [][] m;

	boolean canAfford() {

		return true;
	}

	public int countExchanges(int g1, int s1, int b1, int g2, int s2, int b2) {

		// m = new int[2][3];
		// m[0]= new int[] {g1,s1,b1};
		// m[1]= new int[] {g2,s2,b2};

		int N=0;
		int G = g1 - g2;
		if (G < 0) {
			if ((b1 / 9 + s1) / 9 < g2 - g1) {
				return -1;
			} else if (s1 >= Math.abs(G)) {
				s1 -=9 * Math.abs(G);
				N += Math.abs(G);
			} else {
				s1 =s1%9;
				b1 = b1-81*(Math.abs(G)-N)+9*s1;
				if(b1<0 || b1 < b2) {
					return -1;
				}
				N += 9*(Math.abs(G)-N)-9*s1;
				return  N;
			}

		} else if (g1 == g2) {
			if (s2 > s1) {
				if (b1 / 9 + s1 < s2) {
					return -1;
				}
			}
		}

		return 0;
	}


}
